/* this do-file extracts the relevant variable from the 2007 Community Survey */ 

****************
** CS 2007    ** 
****************

set more off

cd "" /*input directory here with raw data */


use "CS 2007_Person_v1.2_20111206.dta", clear

sort SN

merge SN using "CS2007!housing_F1.dta" 

drop if Scope_Status==0 /* Exclude observations that were not actually sampled */ 

rename SN household_id
rename P01_Pers_Num id
rename P03_Age age
rename P04_Sex sex    
rename P08_Marital_St marital_status
rename P29_Level_Educ education
rename Industry  industry
rename Occupation occupation
rename P37_Sector formal_sector
rename Prv2005_Code province
rename DC2005_Code district
rename P45LASTDAY yc_birth_day
rename P45LASTMO yc_birth_month
rename P45LASTYR yc_birth_year
rename P52_Income_Category income_category
rename DER01_Veso emp_status
rename Weight weight
rename P10_Pop_Group race
rename P11_Born_Prov province_birth
rename P47lASTVS child_alive
rename P41TCEB number_children
rename Mun2005_Code municipality 
rename P36_Work_Status work_status
rename HHIncome hh_income 


rename P26_Attendance school_attend /*Person attends any type of educational institution */ 
recode school_attend (2=0)

 

#delimit ;

keep household_id id age sex marital_status education industry occupation formal_sector   province district 
yc_birth_day yc_birth_month yc_birth_year income_category   
emp_status weight race province_birth child_alive number_children   municipality work_status  
province_birth school_attend hh_income   
H01_Hu H10A_Fridge H10B_Radio H10D_Computer H10C_Television H10E_Telephone H10F_Internet H10G_Postfacil H10H_Cell H11_Tenure H02_Rooms H03_Water_Access H09_Lighting H06_Toilet_Facil;  
#delimit cr 


destring household_id, replace 


***********************
/* Employment Status */ 
***********************

gen status=1 if emp_status==1 
replace status=2 if emp_status==1 & (work_status==3 | work_status==4) 
replace status=3 if emp_status==2
replace status=4 if emp_status==3 


label define status 1 "Employee" 2 "Self-Employed" 3 "Unemployed" 4 "Inactive"
label values status status 


***********************
* Years of Education ** 
***********************

recode education (24=0) (0=1) (1=2) (2=3) (3=4) (4=5) (5=6) (6=7) (7=8) (8=9) (9=10) (10=11) (11=12) (12=12) (13=13) (14=13)(15=12) (16=12) (17/23=14)  
label drop P29_Level_Educ
label var education "Years of Schooling (Careful: Grade 0=1, and 14 indicates any post high school studies)" 
replace education=. if education<0 | education>14
rename education yrs_schooling 


*******************
* Household Assets* 
*******************

* House Type * 

gen house_type=(H01_Hu==1)
label define house_type 0 "Other" 1 "House or Brick Structure"
label values house_type house_type
drop H01_Hu


** Fridge ** 

gen fridge=(H10A_Fridge==1)
drop H10A_Fridge

** Radio ** 

gen radio=(H10B_Radio==1)
drop H10B_Radio

** TV **
  
gen tv=(H10C_Television==1)
drop H10C_Television

** Computer ** 

gen computer=(H10D_Computer==1) 
drop  H10D_Computer

** Cell Phone ** 

gen cell_phone=(H10H_Cell==1)
drop H10H_Cell

* House Tenure ** 

rename H11_Tenure hh_tenure 

* Number of House Rooms *
 
rename H02_Rooms hh_rooms
replace hh_rooms="10" if hh_rooms=="10+"
destring hh_rooms, force replace 

** Water In dewlling ** 

gen hh_water=(H03_Water_Access==1)
drop H03_Water_Access
label var hh_water "Dwelling with water connection"

** Electricity ** 

gen electricity=(H09_Lighting==1)
drop H09_Lighting
label var electricity "Electricity source for lighting"

** Toilet ** 

gen h_toilet=(H06_Toilet_Facil==1 | H06_Toilet_Facil==2 | H06_Toilet_Facil==3 | H06_Toilet_Facil==6)
label var h_toilet "1 if toilet, 0 if latrine or nothing"
drop H06_Toilet_Facil


*******************
/*Household Size */ 
*******************

gen ind=1 
bys household_id: egen household_size=sum(ind)


gen year=2007 /* year variable */ 


save south_community_2007_wber.dta, replace 
